package org.huolala.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.huolala.dao.UsersDao;
import org.huolala.pojo.Users;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/user")
public class UsersController {
	@Resource
	private UsersDao userDao;

	public void setUsersDao(UsersDao userDao) {
		this.userDao = userDao;
	}
	
	@RequestMapping(value="/login",method=RequestMethod.POST)
	public String login(String mobile, String password, HttpSession session) throws Exception {
		Users user = userDao.login(mobile, password);
		if (user != null) {
			session.setAttribute("login_user", user);
			return "redirect:/user/main";
		}
		session.setAttribute("error", "手机号或者密码错误");
		return "redirect:/login.jsp";
	}
	
	@RequestMapping(value="/regist",method=RequestMethod.POST)
	public String regist(Users user) throws Exception {
		userDao.add(user);
		return "redirect:/login.jsp";
	}
	
	@RequestMapping("/main")
	public String main(ModelMap modelMap) throws Exception {
		return "main";
	}
	
}







